package cn.achao.csr.chat.service.impl;

import cn.achao.csr.api.model.entity.ChatUser;
import cn.achao.csr.api.model.entity.LoginUser;
import cn.achao.csr.base.constant.enums.SysSourceEnum;
import cn.achao.csr.base.exception.BusinessException;
import cn.achao.csr.base.utils.ThrowUtils;
import cn.achao.csr.chat.core.build.LoginUserAdapter;
import cn.achao.csr.chat.dao.ChatUserDao;
import cn.achao.csr.chat.service.LoginService;
import cn.achao.csr.security.service.TokenService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author: achao
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class LoginServiceImpl implements LoginService {

    private final ChatUserDao chatUserDao;

    @Override
    public LoginUser loginByWx(Long userId) {
        ChatUser byOpenId = chatUserDao.getById(userId);
        ThrowUtils.throwIf(byOpenId == null,
                BusinessException.fail("微信登录失败", SysSourceEnum.CSR_CHAT.getSysName()));

        return LoginUserAdapter.loginUserBuilder(byOpenId);
    }
}
